

package com.kimo.shop.delivery.comment.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kimo.shop.bean.app.dto.MyOrderDto;
import com.kimo.shop.bean.app.dto.OrderSelfStationDto;
import com.kimo.shop.common.config.Constant;
import com.kimo.shop.common.exception.KimoShopBindException;
import com.kimo.shop.delivery.comment.dao.OrderSelfStationMapper;
import com.kimo.shop.delivery.comment.model.OrderSelfStation;
import com.kimo.shop.delivery.comment.service.OrderSelfStationService;
import com.kimo.shop.service.OrderService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * 自提订单信息表
 *
 * @author kimo-taozhouchuan
 * @date 2020-04-23 15:18:29
 */
@Service
@AllArgsConstructor
public class
OrderSelfStationServiceImpl extends ServiceImpl<OrderSelfStationMapper, OrderSelfStation> implements OrderSelfStationService {

    private final OrderService orderService;
    private final OrderSelfStationMapper orderSelfStationMapper;

    @Override
    public String getNewInfo(Long shopId) {
        return orderSelfStationMapper.getNewInfo(shopId);
    }


    @Override
    public MyOrderDto getOrderByStationCode(Long stationId, Long shopId, String code) {
        MyOrderDto orderByStationCode = orderSelfStationMapper.getOrderByStationCode(stationId, shopId, code);
        if (Objects.isNull(orderByStationCode)){
            // 该提货码，没有对应的订单
            throw new KimoShopBindException("kimo.order.code.no.exist");
        }
        if(StrUtil.isBlank(orderByStationCode.getShopName())) {
            orderByStationCode.setShopName(Constant.PLATFORM_SHOP_NAME);
        }
        return orderByStationCode;
    }


    @Override
    public List<OrderSelfStationDto> getUserStation(String userId) {
        return orderSelfStationMapper.getUserStation(userId);
    }

    @Override
    public List<OrderSelfStation> getStationUserInfo(String userId) {
        return orderSelfStationMapper.getStationUserInfo(userId);
    }

    @Override
    public OrderSelfStationDto getStationByOrderNumber(String orderNumber) {
        return orderSelfStationMapper.getStationByOrderNumber(orderNumber);
    }
}
